package com.dime.basic.service.impl;

import java.util.List;

import com.dime.basic.api.domain.DimeBasemaincheckconclusion;
import com.dime.basic.api.domain.DimeBasemaincheckconclusionadvice;
import com.dime.basic.mapper.DimeBasemaincheckconclusionMapper;
import com.dime.basic.service.IDimeBasemaincheckconclusionadviceService;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.uuid.IdUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dime.basic.mapper.DimeBasemaincheckconclusionadviceMapper;

/**
 * 主检结论对应建议Service业务层处理
 *
 * @author Tiny
 * @date 2023-10-11
 */
@Service
public class DimeBasemaincheckconclusionadviceServiceImpl implements IDimeBasemaincheckconclusionadviceService
{
    @Autowired
    private DimeBasemaincheckconclusionadviceMapper dimeBasemaincheckconclusionadviceMapper;

    @Autowired
    private DimeBasemaincheckconclusionMapper dimeBasemaincheckconclusionMapper;

    /**
     * 查询主检结论对应建议
     *
     * @param id 主检结论对应建议主键
     * @return 主检结论对应建议
     */
    @Override
    public DimeBasemaincheckconclusionadvice selectDimeBasemaincheckconclusionadviceById(String id)
    {
        return dimeBasemaincheckconclusionadviceMapper.selectDimeBasemaincheckconclusionadviceById(id);
    }

    /**
     * 查询主检结论对应建议列表
     *
     * @param dimeBasemaincheckconclusionadvice 主检结论对应建议
     * @return 主检结论对应建议
     */
    @Override
    public List<DimeBasemaincheckconclusionadvice> selectDimeBasemaincheckconclusionadviceList(DimeBasemaincheckconclusionadvice dimeBasemaincheckconclusionadvice)
    {
        return dimeBasemaincheckconclusionadviceMapper.selectDimeBasemaincheckconclusionadviceList(dimeBasemaincheckconclusionadvice);
    }

    /**
     * 新增主检结论对应建议
     *
     * @param dimeBasemaincheckconclusionadvice 主检结论对应建议
     * @return 结果
     */
    @Override
    public int insertDimeBasemaincheckconclusionadvice(DimeBasemaincheckconclusionadvice dimeBasemaincheckconclusionadvice)
    {
        dimeBasemaincheckconclusionadvice.setId(IdUtils.fastUUID());
        dimeBasemaincheckconclusionadvice.setCreateTime(DateUtils.getNowDate());
        dimeBasemaincheckconclusionadvice.setCreateBy(SecurityUtils.getUsername());
        setDimeBasemaincheckconclusionadvice(dimeBasemaincheckconclusionadvice);
        return dimeBasemaincheckconclusionadviceMapper.insertDimeBasemaincheckconclusionadvice(dimeBasemaincheckconclusionadvice);
    }


    /**
     * 修改主检结论对应建议
     *
     * @param dimeBasemaincheckconclusionadvice 主检结论对应建议
     * @return 结果
     */
    @Override
    public int updateDimeBasemaincheckconclusionadvice(DimeBasemaincheckconclusionadvice dimeBasemaincheckconclusionadvice)
    {
        dimeBasemaincheckconclusionadvice.setUpdateBy(SecurityUtils.getUsername());
        dimeBasemaincheckconclusionadvice.setUpdateTime(DateUtils.getNowDate());
        setDimeBasemaincheckconclusionadvice(dimeBasemaincheckconclusionadvice);
        return dimeBasemaincheckconclusionadviceMapper.updateDimeBasemaincheckconclusionadvice(dimeBasemaincheckconclusionadvice);
    }

    /**
     * 批量删除主检结论对应建议
     *
     * @param ids 需要删除的主检结论对应建议主键
     * @return 结果
     */
    @Override
    public int deleteDimeBasemaincheckconclusionadviceByIds(String[] ids)
    {
        return dimeBasemaincheckconclusionadviceMapper.deleteDimeBasemaincheckconclusionadviceByIds(ids);
    }

    /**
     * 删除主检结论对应建议信息
     *
     * @param id 主检结论对应建议主键
     * @return 结果
     */
    @Override
    public int deleteDimeBasemaincheckconclusionadviceById(String id)
    {
        return dimeBasemaincheckconclusionadviceMapper.deleteDimeBasemaincheckconclusionadviceById(id);
    }

    private void setDimeBasemaincheckconclusionadvice(DimeBasemaincheckconclusionadvice dimeBasemaincheckconclusionadvice) {
        if (dimeBasemaincheckconclusionadvice.getPassTag()==null){
            dimeBasemaincheckconclusionadvice.setPassTag(0L);
        }
        if (dimeBasemaincheckconclusionadvice.getRecheckTag()==null){
            dimeBasemaincheckconclusionadvice.setRecheckTag("0");
        }
        if (StringUtils.isNotEmpty(dimeBasemaincheckconclusionadvice.getMainconclusionId())){
            DimeBasemaincheckconclusion dimeBasemaincheckconclusion = dimeBasemaincheckconclusionMapper.selectDimeBasemaincheckconclusionById(dimeBasemaincheckconclusionadvice.getMainconclusionId());
            if (dimeBasemaincheckconclusion != null){
                dimeBasemaincheckconclusionadvice.setMainconclusionName(dimeBasemaincheckconclusion.getConclusion());
            }
        }
    }
}